<template>
  <div class="nucleicAcidBox">
    <div class="line">
      <div class="th" style="flex: 0.5">核酸结果</div>
      <div class="th" style="flex: 1">采集时间</div>
      <div class="th" style="flex: 1">采集地点</div>
      <div class="th" style="flex: 1">检测时间</div>
      <div class="th" style="flex: 1">检测机构</div>
    </div>
    <div class="table scroll" ref="table_query_nucleicacid" id="table_query_nucleicacid">
      <div class="tr" v-for="(item, index) in tableData" :key="index" ref="tableRef">
        <div style="flex: 0.5">
          {{ item.checkStatus }}
        </div>
        <div style="flex: 1">
          {{ item.checkStatus }}
        </div>
        <div style="flex: 1" class="overLine">
          <el-tooltip
            class="box-item"
            effect="dark"
            :disabled="item?.company?.length < 17"
            :content="item.company"
            placement="top"
          >
            {{ item.company }}
          </el-tooltip>
        </div>
        <div style="flex: 1">
          {{ item.checkTime }}
        </div>
        <div style="flex: 1" class="overLine">
          <el-tooltip
            class="box-item"
            effect="dark"
            :disabled="item?.address?.length < 17"
            :content="item.address"
            placement="top"
          >
            {{ item.address }}
          </el-tooltip>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { nextTick } from 'vue'

export default {
  name: 'nucleicAcid',
  props: {
    param: {
      type: Array,
      default: () => [],
    },
  },
  watch: {
    param: {
      deep: true,
      immediate: true,
      handler: function (val) {
        if (val !== undefined) {
          this.tableData = val
        }
      },
    },
  },
  data() {
    return {
      tableData: [],
    }
  },
  mounted() {
    this.autoScroll()
  },
  methods: {
    autoScroll() {
      const el = this.$refs.table_query_nucleicacid
      const elHeight = el.offsetHeight
      const sHeight = el.scrollHeight
      setInterval(() => {
        if (el.scrollTop < sHeight - elHeight) {
          el.scrollTop++
        } else {
          el.scrollTop = 0
        }
      }, 50)
    },
  },
}
</script>

<style lang="less" scoped>
.nucleicAcidBox {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .line {
    display: flex;
    justify-content: center;
    width: 100%;
    height: 44px;
    font-size: 14px;
    color: #ffffff;

    .th {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
  .table {
    flex: 1;
    width: 100%;
    overflow: hidden auto;

    .tr {
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      height: 56px;
      font-size: 14px;
      color: #ffffff;
      text-align: center;

      &:nth-child(odd) {
        background: rgba(19, 181, 177, 0.4);
      }

      .overLine {
        overflow: hidden;
        white-space: nowrap;
        word-break: break-all;
        word-wrap: break-word;
        text-overflow: ellipsis;
        -o-text-overflow: ellipsis;
      }
    }
  }
}
</style>
